package thinkinginjava.enumerated;

import java.util.EnumSet;
import java.util.Random;

enum Outcome{WIN, LOSE, DRAW}
interface Item {
	Outcome compete(Item item);
	Outcome eval(Paper paper);
	Outcome eval(Scissors scissors);
	Outcome eval(Rock rock);
}

class Paper implements Item {
	public Outcome compete(Item item) {	return item.eval(this);	}
	public Outcome eval(Paper paper) {	return Outcome.DRAW;	}
	public Outcome eval(Scissors scissors) {	return Outcome.LOSE;	}
	public Outcome eval(Rock rock) {	return Outcome.WIN;		}
	public String toString() { return "Paper"; }
}
class Scissors implements Item {
	public Outcome compete(Item item) {	return item.eval(this);	}
	public Outcome eval(Paper paper) {	return Outcome.WIN;	}
	public Outcome eval(Scissors scissors) {	return Outcome.DRAW;	}
	public Outcome eval(Rock rock) {	return Outcome.LOSE;		}
	public String toString() { return "Scissors"; }
}
class Rock implements Item {
	public Outcome compete(Item item) {	return item.eval(this);	}
	public Outcome eval(Paper paper) {	return Outcome.LOSE;	}
	public Outcome eval(Scissors scissors) {	return Outcome.WIN;	}
	public Outcome eval(Rock rock) {	return Outcome.DRAW;		}
	public String toString() { return "Rock"; }
}

public class RoShamBo {
	private static Random rand = new Random(47);
	public static Item newItem() {
		switch(rand.nextInt(3)) {
		default:
		case 0: return new Paper();
		case 1: return new Scissors();
		case 2: return new Rock();
		}
	}
	
	public static void match(Item it1, Item it2) {
		System.out.println(it1 + " vs. " + it2 + " : " + it1.compete(it2));
	}
	
	public static void main(String[] args) {
		match(newItem(), newItem());
	}
}
